<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>huggingface_transformer笔记 | zapqwe block</title><meta name="author" content="laptony"><meta name="copyright" content="laptony"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="huggingface_transformer教程笔记整理">
<meta property="og:type" content="article">
<meta property="og:title" content="huggingface_transformer笔记">
<meta property="og:url" content="https://sswd123.gitee.io/posts/27840/index.html">
<meta property="og:site_name" content="zapqwe block">
<meta property="og:description" content="huggingface_transformer教程笔记整理">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg">
<meta property="article:published_time" content="2023-01-20T09:00:56.000Z">
<meta property="article:modified_time" content="2023-01-20T11:52:05.327Z">
<meta property="article:author" content="laptony">
<meta property="article:tag" content="AI">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://sswd123.gitee.io/posts/27840/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'huggingface_transformer笔记',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-01-20 19:52:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- -音乐--><div class="aplayer" data-id="7455077979" data-server="tencent" data-type="playlist" data-fixed="true" data-listFolded="false" data-order="random" data-preload="none"></div><link rel="stylesheet" href="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.css"><script src="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@1.2.0/dist/Meting.min.js"></script><link rel="stylesheet" href="/css/font.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.min.css"/>
<style>#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags:before {content:"\A";
  white-space: pre;}#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags > .article-meta__separator{display:none}</style>
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (true) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/11.gif" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">12</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">9</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-homef"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fas fa-camera"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">zapqwe block</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-homef"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fas fa-camera"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">huggingface_transformer笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-01-20T09:00:56.000Z" title="发表于 2023-01-20 17:00:56">2023-01-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-01-20T11:52:05.327Z" title="更新于 2023-01-20 19:52:05">2023-01-20</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E7%AC%94%E8%AE%B0/">笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="huggingface_transformer笔记"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Transformers"><a href="#Transformers" class="headerlink" title="Transformers"></a>Transformers</h1><p>transformer提供了API和工具，可以轻松下载和训练最先进的预训练模型。使用预训练的模型可以降低计算成本、碳足迹，并节省从头训练模型所需的时间和资源。这些模型支持不同模式的常见任务，例如：<br>NLP:文本分类、命名实体识别、问题解答、语言模型、摘要、翻译、多选和文本生成<br>计算机视觉：图像分类、物体检测和分割。<br>音频：自动语音识别和音频分类。<br>多模态：表格问题解答、光学字符识别、从扫描文档中提取信息、视频分类和视觉问题解答。<br>transformers 支持框架（pytorch,tensorflow,jax）互相操作，提供了使用不同框架在模型不同生命周期，训练模型在一个框架可以只有三行代码，然后在另一个框架下加载，也提供转换格式到ONNX and TorchScript 在生产环境进行部署。</p>
<h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><p><strong>Get_started</strong>:提供了教程帮助快速浏览相关库和安装说明以启动和运行。<br><strong>Tutorials</strong>:如果你是初学者，这是一个很好的开始。本节将帮助您掌握开始使用库所需的基本技能。<br><strong>How-to guides</strong>: 向您展示如何实现特定目标，例如为语言建模微调预训练模型，或如何编写和共享自定义模型<br><strong>Conceptual guides</strong>:对模型、任务和设计理念背后的基本概念和想法进行了更多的讨论和解释<br><strong>Api</strong>:描述类和函数</p>
<h2 id="get-strarted"><a href="#get-strarted" class="headerlink" title="get_strarted:"></a>get_strarted:</h2><p>开始使用transformers.无论您是开发人员还是日常用户，本章都将帮助您入门。向你展示如何使用pipeline().对于推理，通过AutoClass类加载预训练模型，同时利用pytorch训练模型。对于学习者，我们建议下一步学习tutorials这一章节以更深入地解释这里介绍的概念。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pip install torch</span><br><span class="line">pip install transformers datasets</span><br></pre></td></tr></table></figure>
<p>pipeline()是最简单的方式通过预训练模型进行推理。该方法开箱即用，下面图展示了支持的任务。<br><img src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/20230120173347.png"></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">from transformers import pipeline</span><br><span class="line">classifier = pipeline(&quot;sentiment-analysis&quot;)</span><br><span class="line">classifier(&quot;We are very happy to show you the 🤗 Transformers library.&quot;)</span><br><span class="line"></span><br><span class="line">results = classifier([&quot;We are very happy to show you the 🤗 Transformers library.&quot;, &quot;We hope you don&#x27;t hate it.&quot;])</span><br><span class="line">for result in results:</span><br><span class="line">    print(f&quot;label: &#123;result[&#x27;label&#x27;]&#125;, with score: &#123;round(result[&#x27;score&#x27;], 4)&#125;&quot;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>pipeline（）还可以为您喜欢的任何任务迭代整个数据集。对于这个示例，让我们选择自动语音识别作为我们的任务：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">import torch</span><br><span class="line">from transformers import pipeline</span><br><span class="line">speech_recognizer = pipeline(&quot;automatic-speech-recognition&quot;, model=&quot;facebook/wav2vec2-base-960h&quot;)</span><br><span class="line"></span><br><span class="line">from datasets import load_dataset, Audio</span><br><span class="line">dataset = load_dataset(&quot;PolyAI/minds14&quot;, name=&quot;en-US&quot;, split=&quot;train&quot;)</span><br><span class="line">dataset = dataset.cast_column(&quot;audio&quot;, Audio(sampling_rate=speech_recognizer.feature_extractor.sampling_rate))</span><br><span class="line">#dataset取前4个实例</span><br><span class="line">result = speech_recognizer(dataset[:4][&quot;audio&quot;])</span><br><span class="line">print([d[&quot;text&quot;] for d in result])</span><br></pre></td></tr></table></figure>
<p>在pipeline（）中使用另一个模型和分词器 ，pipeline（）可以容纳Hub中的任何模型，从而可以很容易地将pipeline 用于其他用例。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">model_name = &quot;nlptown/bert-base-multilingual-uncased-sentiment&quot;</span><br><span class="line">from transformers import AutoTokenizer, AutoModelForSequenceClassification</span><br><span class="line"></span><br><span class="line">model = AutoModelForSequenceClassification.from_pretrained(model_name)</span><br><span class="line">tokenizer = AutoTokenizer.from_pretrained(model_name)</span><br><span class="line">classifier = pipeline(&quot;sentiment-analysis&quot;, model=model, tokenizer=tokenizer)</span><br><span class="line">classifier(&quot;Nous sommes très heureux de vous présenter la bibliothèque 🤗 Transformers.&quot;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>下面详细分析AutoModelForSequenceClassification，AutoTokenizer</p>
<h3 id="AutoClass"><a href="#AutoClass" class="headerlink" title="AutoClass"></a>AutoClass</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">from transformers import AutoTokenizer</span><br><span class="line">model_name = &quot;nlptown/bert-base-multilingual-uncased-sentiment&quot;</span><br><span class="line">tokenizer = AutoTokenizer.from_pretrained(model_name)</span><br><span class="line">encoding = tokenizer(&quot;We are very happy to show you the Transformers library.&quot;)</span><br><span class="line">print(encoding)</span><br></pre></td></tr></table></figure>
<p>okenizer返回一个字典，其中包含：<br>input_ids：tocken的数字表示。<br>attention_mask：指示应该关注哪些tocken。</p>
<p>分词器还可以接受输入列表，并填充和截断文本以返回具有统一长度的批处理。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">pt_batch = tokenizer(</span><br><span class="line">    [&quot;We are very happy to show you the 🤗 Transformers library.&quot;, &quot;We hope you don&#x27;t hate it.&quot;],</span><br><span class="line">    padding=True,</span><br><span class="line">    truncation=True,</span><br><span class="line">    max_length=512,</span><br><span class="line">    return_tensors=&quot;pt&quot;,</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<p>Transformers提供了一种简单统一的加载预训练实例的方法。这意味着您可以像加AutoTokenizer一样加载AutoModel。唯一的区别是为任务选择正确的AutoModel。对于文本（或序列）分类，应加载AutoModelForSequenceClassification。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">from transformers import AutoModelForSequenceClassification</span><br><span class="line">model_name = &quot;nlptown/bert-base-multilingual-uncased-sentiment&quot;</span><br><span class="line">pt_model = AutoModelForSequenceClassification.from_pretrained(model_name)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>现在将预处理的一批输入直接传递给模型。你只需要通过添加**,模型在logits属性中输出最终激活。将softmax函数应用于逻辑以检索概率.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">pt_outputs = pt_model(**pt_batch)</span><br><span class="line">from torch import nn</span><br><span class="line">pt_predictions = nn.functional.softmax(pt_outputs.logits, dim=-1)</span><br><span class="line">print(pt_predictions)</span><br></pre></td></tr></table></figure>
<p>对模型进行微调后，可以使用PreTrainedModel.save_pretrained（）保存模型：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pt_save_directory = &quot;./pt_save_pretrained&quot;</span><br><span class="line">tokenizer.save_pretrained(pt_save_directory)</span><br><span class="line">pt_model.save_pretrained(pt_save_directory)</span><br></pre></td></tr></table></figure>
<p>当您准备好再次使用该模型时，请使用PreTrainedModel.from_precoined（）重新加载该模型：</p>
<p><code>pt_model = AutoModelForSequenceClassification.from_pretrained(&quot;./pt_save_pretrained&quot;)</code><br>一个特别酷的特性是能够保存模型并将其重新加载为PyTorch或TensorFlow模型。from_pt或from_tf参数可以将模型从一个框架转换为另一个框架.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">from transformers import AutoModel</span><br><span class="line">tokenizer = AutoTokenizer.from_pretrained(tf_save_directory)</span><br><span class="line">pt_model = AutoModelForSequenceClassification.from_pretrained(tf_save_directory, from_tf=True)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="Custom-model-builds"><a href="#Custom-model-builds" class="headerlink" title="Custom model builds"></a>Custom model builds</h3><p>您可以修改模型的配置类以更改模型的构建方式。该配置指定模型的属性，例如隐藏层或关注点的数量。从自定义配置类初始化模型时，可以从头开始。模型属性是随机初始化的，在使用它获得有意义的结果之前，您需要训练模型。<br>首先导入AutoConfig，然后加载要修改的预处理模型。在AutoConfig.from_precoined（）中，可以指定要更改的属性，例如关注点的数量.</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">from transformers import AutoConfig</span><br><span class="line">my_config = AutoConfig.from_pretrained(&quot;distilbert-base-uncased&quot;, n_heads=12)</span><br><span class="line">from transformers import AutoModel</span><br><span class="line">my_model = AutoModel.from_config(my_config)</span><br></pre></td></tr></table></figure>

<h3 id="Trainer-a-PyTorch-optimized-training-loop"><a href="#Trainer-a-PyTorch-optimized-training-loop" class="headerlink" title="Trainer - a PyTorch optimized training loop"></a>Trainer - a PyTorch optimized training loop</h3><p>所有模型都是标准的torch.nn.Module，因此您可以在任何典型的训练循环中使用它们。虽然您可以编写自己的训练循环，但Transformers为PyTorch提供了一个Trainner，其中包含基本的训练循环并为分布式训练、混合精度等功能添加了额外的功能。根据您的任务，您通常会将以下参数传递给Trainer。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">from transformers import AutoModelForSequenceClassification</span><br><span class="line">model = AutoModelForSequenceClassification.from_pretrained(&quot;distilbert-base-uncased&quot;)</span><br><span class="line"></span><br><span class="line">from transformers import TrainingArguments</span><br><span class="line">training_args = TrainingArguments(</span><br><span class="line">    output_dir=&quot;path/to/save/folder/&quot;,</span><br><span class="line">    learning_rate=2e-5,</span><br><span class="line">    per_device_train_batch_size=8,</span><br><span class="line">    per_device_eval_batch_size=8,</span><br><span class="line">    num_train_epochs=2,</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">from transformers import AutoTokenizer</span><br><span class="line">tokenizer = AutoTokenizer.from_pretrained(&quot;distilbert-base-uncased&quot;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">from datasets import load_dataset</span><br><span class="line">dataset = load_dataset(&quot;rotten_tomatoes&quot;)  # doctest: +IGNORE_RESULT</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def tokenize_dataset(dataset):</span><br><span class="line">    return tokenizer(dataset[&quot;text&quot;])</span><br><span class="line">dataset = dataset.map(tokenize_dataset, batched=True)</span><br><span class="line"></span><br><span class="line">from transformers import DataCollatorWithPadding</span><br><span class="line">data_collator = DataCollatorWithPadding(tokenizer=tokenizer)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">from transformers import Trainer</span><br><span class="line"></span><br><span class="line">trainer = Trainer(</span><br><span class="line">    model=model,</span><br><span class="line">    args=training_args,</span><br><span class="line">    train_dataset=dataset[&quot;train&quot;],</span><br><span class="line">    eval_dataset=dataset[&quot;test&quot;],</span><br><span class="line">    tokenizer=tokenizer,</span><br><span class="line">    data_collator=data_collator,</span><br><span class="line">)  # doctest: +SKIP</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">trainer.train()</span><br></pre></td></tr></table></figure>
<p>您可以通过将Trainer中的方法子类化来定制训练循环行为。这允许您自定义诸如损失函数、优化器和调度器等功能.</p>
<h3 id="下一步"><a href="#下一步" class="headerlink" title="下一步"></a>下一步</h3><p>现在，您已经完成了transformers快速教程，请查看我们的Guide，了解如何进行更具体的操作，如编写自定义模型、为任务微调模型，以及如何使用脚本训练模型。如果您有兴趣了解更多有关transformers核心概念的信息，请喝杯咖啡，继续学习！</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://sswd123.gitee.io">laptony</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://sswd123.gitee.io/posts/27840/">https://sswd123.gitee.io/posts/27840/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://sswd123.gitee.io" target="_blank">zapqwe block</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/AI/">AI</a></div><div class="post_share"><div class="social-share" data-image="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/13.jpg" target="_blank"><img class="post-qr-code-img" src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/13.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/12.jpg" target="_blank"><img class="post-qr-code-img" src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/12.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/posts/29414/"><img class="next-cover" src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">知识增强的文本生成报告笔记</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/10059/" title="AI笔记"><img class="cover" src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/A547B66ABDA63D737A9376686FDA3736.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-09</div><div class="title">AI笔记</div></div></a></div><div><a href="/posts/29414/" title="知识增强的文本生成报告笔记"><img class="cover" src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-14</div><div class="title">知识增强的文本生成报告笔记</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/11.gif" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">laptony</div><div class="author-info__description">敏于思考，锐于实现</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">12</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">9</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/zapqqqwe"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/zapqqqwe" target="_blank" title="Github"><i class="fas fa-github"></i></a><a class="social-icon" href="mailto:2496524403@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">折腾中学会知识，互访中找到友情，写作中读懂人生，坚持中找到方向。</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Transformers"><span class="toc-number">1.</span> <span class="toc-text">Transformers</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95"><span class="toc-number">1.1.</span> <span class="toc-text">目录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#get-strarted"><span class="toc-number">1.2.</span> <span class="toc-text">get_strarted:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#AutoClass"><span class="toc-number">1.2.1.</span> <span class="toc-text">AutoClass</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Custom-model-builds"><span class="toc-number">1.2.2.</span> <span class="toc-text">Custom model builds</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Trainer-a-PyTorch-optimized-training-loop"><span class="toc-number">1.2.3.</span> <span class="toc-text">Trainer - a PyTorch optimized training loop</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%8B%E4%B8%80%E6%AD%A5"><span class="toc-number">1.2.4.</span> <span class="toc-text">下一步</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://www-1305197828.cos.ap-beijing.myqcloud.com/imgs/5af17f7f881b11ebb6edd017c2d2eca2.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023  <i id="heartbeat" class="fa fas fa-heartbeat"></i> laptony</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my  <a href="https://sswd123.gitee.io/">blog</a>!</div></div><head><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"></head></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'ouV9RVxe71Vu4hdUP93QtOs1-gzGzoHsz',
      appKey: 'laBz1asytkOHj9NfuZVJogqf',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script src="https://cdn.jsdelivr.net/npm/blueimp-md5/js/md5.min.js"></script><script>window.addEventListener('load', () => {
  const changeContent = (content) => {
    if (content === '') return content

    content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
    content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
    content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
    content = content.replace(/<[^>]+>/g,"") // remove html tag

    if (content.length > 150) {
      content = content.substring(0,150) + '...'
    }
    return content
  }

  const getIcon = (icon, mail) => {
    if (icon) return icon
    let defaultIcon = '?d=monsterid'
    let iconUrl = `https://gravatar.loli.net/avatar/${md5(mail.toLowerCase()) + defaultIcon}`
    return iconUrl
  }

  const generateHtml = array => {
    let result = ''

    if (array.length) {
      for (let i = 0; i < array.length; i++) {
        result += '<div class=\'aside-list-item\'>'

        if (true) {
          const name = 'src'
          result += `<a href='${array[i].url}' class='thumbnail'><img ${name}='${array[i].avatar}' alt='${array[i].nick}'></a>`
        }

        result += `<div class='content'>
        <a class='comment' href='${array[i].url}' title='${array[i].content}'>${array[i].content}</a>
        <div class='name'><span>${array[i].nick} / </span><time datetime="${array[i].date}">${btf.diffDate(array[i].date, true)}</time></div>
        </div></div>`
      }
    } else {
      result += '没有评论'
    }

    let $dom = document.querySelector('#card-newest-comments .aside-list')
    $dom.innerHTML= result
    window.lazyLoadInstance && window.lazyLoadInstance.update()
    window.pjax && window.pjax.refresh($dom)
  }

  const getComment = () => {
    const serverURL = 'https://ouV9RVxe.api.lncldglobal.com'

    var settings = {
      "method": "GET",
      "headers": {
        "X-LC-Id": 'ouV9RVxe71Vu4hdUP93QtOs1-gzGzoHsz',
        "X-LC-Key": 'laBz1asytkOHj9NfuZVJogqf',
        "Content-Type": "application/json"
      },
    }

    fetch(`${serverURL}/1.1/classes/Comment?limit=6&order=-createdAt`,settings)
      .then(response => response.json())
      .then(data => {
        const valineArray = data.results.map(function (e) {
          return {
            'avatar': getIcon(e.QQAvatar, e.mail),
            'content': changeContent(e.comment),
            'nick': e.nick,
            'url': e.url + '#' + e.objectId,
            'date': e.updatedAt,
          }
        })
        saveToLocal.set('valine-newest-comments', JSON.stringify(valineArray), 10/(60*24))
        generateHtml(valineArray)
      }).catch(e => {
        const $dom = document.querySelector('#card-newest-comments .aside-list')
        $dom.innerHTML= "无法获取评论，请确认相关配置是否正确"
      }) 
  }

  const newestCommentInit = () => {
    if (document.querySelector('#card-newest-comments .aside-list')) {
      const data = saveToLocal.get('valine-newest-comments')
      if (data) {
        generateHtml(JSON.parse(data))
      } else {
        getComment()
      }
    }
  }

  newestCommentInit()
  document.addEventListener('pjax:complete', newestCommentInit)
})</script><div><canvas id="snow" style="position:fixed;top:0;left:0;width:100%;height:100%;z-index:99999;pointer-events:none"></canvas></div><script>const notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));</script><script async type="text/javascript" src="https://cdn.jsdelivr.net/gh/Candinya/Kratos-Rebirth@latest/source/js/snow.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="I,LOVE,YOU" data-fontsize="15px" data-random="false" async="async"></script><div class="aplayer" data-id="7455077979" data-server="tencent" data-type="playlist" data-fixed="true" data-listFolded="false" data-order="random" data-preload="none"></div><link rel="stylesheet" href="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.css"><script src="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@1.2.0/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"left","width":100,"height":200},"mobile":{"show":true},"rect":{"opacity":0.5},"log":false});</script></body></html>